/*
	FileName : H7xx_Led.c
	Description :
	Created on 2013.01.18 by ZZP.

	Revision History:

*/

#include "bsp.h"
#include "H7xx_Led.h"

///

static __IO uint32_t WkLedTm;
static __IO uint32_t RxLedTm;
static __IO uint32_t TxLedTm;
static __IO uint32_t MiscLedTm;

void H7xx_WkLed(void);
void H7xx_RxLed(void);

///////////////////////////////////////////////////////////
///			Global function realizations
///////////////////////////////////////////////////////////
void H7xx_InitLED(void)
{
	BSP_LED_Init();
}


void H7xx_PowOnLedFlash(void)
{
	BSP_LED_On(LED_STM);
  	BSP_LED_On(LED_ERR);
  	BSP_LED_On(LED_CFC);
	BSP_LED_On(LED_DTU);
  	BSP_LED_On(LED_MISC);
	BSP_LED_Off(LED_USB);///on

  	MyInfo.SysTm = 0;
	while (MyInfo.SysTm < 500){}

  	BSP_LED_Off(LED_STM);
  	BSP_LED_Off(LED_ERR);
  	BSP_LED_Off(LED_CFC);
	BSP_LED_Off(LED_DTU);
  	BSP_LED_Off(LED_MISC);
	BSP_LED_On(LED_USB);///off

	MyInfo.SysTm = 0;
	while (MyInfo.SysTm < 300){}
}

void H7xx_BiosLed(void)
{
	H7xx_WkLed();
	H7xx_RxLed();
}




///////////////////////////////////////////////////////////
///			Local function realizations
///////////////////////////////////////////////////////////
void H7xx_WkLed(void)
{
	if (MyInfo.RdyFlag){
		
		if (WkLedTm >= 500){
			
			BSP_LED_On(LED_STM);
			BSP_LED_On(LED_ERR);
			BSP_LED_On(LED_MISC);
			WkLedTm = 0;
		}
		else{
			
			WkLedTm++;
			if (WkLedTm == 200){
				
				BSP_LED_Off(LED_STM);
				BSP_LED_Off(LED_ERR);
				BSP_LED_Off(LED_MISC);
			}
		}
	}
}


void H7xx_RxLed(void)
{
	if (MyInfo.RdyFlag){
		
		if (MyInfo.RxFlag){
			
			if (RxLedTm >= 100){
				
				BSP_LED_Off(LED_CFC);
				RxLedTm = 0;
				MyInfo.RxFlag--;
			}
			else{
				
				if ((RxLedTm % 50) == 0)
					BSP_LED_On(LED_CFC); 			
				else if ((RxLedTm % 20) == 0)
					BSP_LED_Off(LED_CFC);
				RxLedTm++;
			}
		}
		else{
			
			BSP_LED_Off(LED_CFC);
			RxLedTm = 0;
		}
	}
}







